import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {BaseService} from '../../../shared/service/base.service';

@Component({
  selector: 'app-brand-manage-edit',
  templateUrl: './brand-manage-edit.component.html',
  styleUrls: ['./brand-manage-edit.component.less']
})
export class BrandManageEditComponent implements OnInit {

// 模态框显隐
  @Input()
  isVisible = false;
  // 父子互传值
  @Output()
  emit: EventEmitter<any> = new EventEmitter();
  // 提交时提交按钮是否加载中
  isOkLoading: any;
  // 模态框表单
  formModel: FormGroup;
  title: any;
  constructor(private fb: FormBuilder, private baseService: BaseService) {
    this.buildForm();
  }

  ngOnInit(): void {

  }
  buildForm() {
    this.formModel = this.fb.group({
      id: [0,[]],
      title: [null, [Validators.required]],
      status: [false,[]]
    });
  }

  // 取消
  handleCancel() {
    this.isVisible = false;
    this.emit.emit(this.isVisible);
  }

  // 确认
  handleOk() {
    this.isOkLoading = true;
    if (!this.baseService.zorro.validateFormValidate(this.formModel)) {
      this.isOkLoading = false;
      return;
    }

    if (!this.isOkLoading) {
      return;
    }
  }

}
